package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.ServiceDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class Controller {
    @Autowired
    ServiceDao serviceDao;
    @RequestMapping("showSum")
    public Object showSum(){
        List<Map> maps = serviceDao.showSum();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        jsonObject.put("data",maps.get(0).get("s"));
        return jsonObject;
    }

    @RequestMapping("showZhu")
    public Object showZhu(){
        List<Map> maps = serviceDao.showZhu();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray nameArray = new JSONArray();
        JSONArray seriesArray = new JSONArray();
        JSONObject seriesObject = new JSONObject();
        seriesObject.put("name","占比");
        JSONArray dataArray = new JSONArray();
        seriesObject.put("data",dataArray);
        seriesArray.add(seriesObject);
        for (Map map : maps) {
            nameArray.add(map.get("tm_name"));
            dataArray.add(map.get("s"));
        }
        dataObject.put("categories",nameArray);
        dataObject.put("series",seriesArray);
        jsonObject.put("data",dataObject);
        return jsonObject;
    }

    @RequestMapping("showShen")
    public Object showShen(){
        List<Map> maps = serviceDao.showShen();
        JSONObject jsonObject = new JSONObject();

        jsonObject.put("status",0);
        jsonObject.put("msg","");

        JSONObject dataObject = new JSONObject();

        JSONArray dataArray = new JSONArray();

        for (Map map : maps) {
            JSONObject object = new JSONObject();
            object.put("name",map.get("name"));
            object.put("value",map.get("s"));
            dataArray.add(object);
        }

        dataObject.put("mapData",dataArray);

        jsonObject.put("data",dataObject);

        return jsonObject;
    }


    @RequestMapping("showBing")
    public Object showBing(){
        List<Map> maps = serviceDao.showBing();
        JSONObject jsonObject = new JSONObject();

        jsonObject.put("status",0);
        jsonObject.put("msg","");

        JSONArray dataArray = new JSONArray();

        for (Map map : maps) {
            JSONObject dataObject = new JSONObject();
            dataObject.put("name",map.get("tm_name"));
            dataObject.put("value",map.get("s"));
            dataArray.add(dataObject);
        }

        jsonObject.put("data",dataArray);

        return jsonObject;
    }
}
















